
package com.desksoft.ecommerce.util.html.element.format.dataformat;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import com.desksoft.ecommerce.vo.KeyAndValue;

/**
 * 枚举类型格式化
 * @author Administrator
 *
 */
public class EnumFormat extends DataFormat {

	protected List<KeyAndValue> kvL;
	
	public EnumFormat(Element element) {
		super(element);
		this.kvL = parse(element.elements("option"));
	}
	
	public List<KeyAndValue> parse(List<Element> elements){
		List<KeyAndValue> kvL = new ArrayList<KeyAndValue>();
		if (elements == null){return kvL;}
		for (Element elmt : elements){
			kvL.add(new KeyAndValue(elmt.attributeValue("value"), elmt.getText()));
		}
		return kvL;
	}

	@Override
	public String append() {
		StringBuffer html = new StringBuffer();
		for (KeyAndValue kv : kvL){
			html.append("<span value=" + kv.getKey() + "  text=" + kv.getValue() + "></span>");
		}
		return html.toString();
	}

}
